﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;

using XJX.DataLayer;

namespace XJX.BusinessLayer
{
    public class Evaluate
    {
        private string ConnToData;

        public Evaluate(string newConnectionString)
        {
            ConnToData = newConnectionString;
        }

        //添加书评
        public bool Add_New_Evaluate(string BID, string UID, string Econtent, int Egrade, out int ReturnValue, out string ReturnFieldValue)
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Evaluate(ConnToData).Add_New_Evaluate(BID,UID,Econtent,Egrade, out ReturnValue, out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        //得到一本书的所有书评
        public Hashtable Get_One_Book_Evaluate_From_BID(string BID, int PageIndex, int PageSize)
        {
            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();
            int PageCount = 0;
            int TotalCount = 0;

            DataSet ds = new XJX.DataLayer.Evaluate(ConnToData).Get_One_Book_Evaluate_From_BID(BID, "Book_Evaluate", PageIndex, PageSize, out PageCount, out TotalCount);
            dt = ds.Tables[0];

            ArrayList data = Common.DataTable2ArrayList(dt);

            ht["PageCount"] = PageCount;//页数,将在哈希表中输出成字符串。
            ht["RecordCount"] = TotalCount;//记录总数
            ht["rows"] = data;

            return ht;
        }

                //屏敝一条书评
        public bool Shielding_One_Evaluate_From_EID(string EID)
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Evaluate(ConnToData).Shielding_One_Evaluate_From_EID(EID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        //添加内容评价
        public bool Ev_Add_New_Evaluate
        (
            string ItemName,
            string ParentID,
            string UID,
            string Content,
            out int ReturnValue,
            out string ReturnFieldValue
        )
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Evaluate(ConnToData).Ev_Add_New_Evaluate(ItemName,ParentID, UID, Content, out ReturnValue, out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        //删除内容的一条评价记录
        public bool Ev_Del_One_ContentEvaluate_From_ID(string ID, string UID)
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Evaluate(ConnToData).Ev_Del_One_ContentEvaluate_From_ID(ID, UID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        //添加点赞,或者去掉点赞
        public bool Ev_Add_New_Credit
        (
            string ItemName,
            string ParentID,
            string UID
        )
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Evaluate(ConnToData).Ev_Add_New_Credit(ItemName, ParentID, UID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }



        //某个家庭针对某主题发表的所有回复内容
        public Hashtable Ev_Get_One_Family_ContentEvaluate_By_UID
            (
            string ItemName,
            string ParentID,
            string UID,

            int PageIndex,
            int PageSize
            )
        {
            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();
            int PageCount = 0;
            int TotalCount = 0;


            DataSet ds = new XJX.DataLayer.Evaluate(ConnToData).Ev_Get_One_Family_ContentEvaluate_By_UID
                    (ItemName, ParentID, UID, "One_Family_ContentEvaluate", PageIndex, PageSize, out PageCount, out TotalCount);
            dt = ds.Tables[0];

            ArrayList data = Common.DataTable2ArrayList(dt);

            ht["PageCount"] = PageCount;//页数,将在哈希表中输出成字符串。
            ht["RecordCount"] = TotalCount;//记录总数
            ht["rows"] = data;

            return ht;
        }


        //一般用户或者管理员获取某主题回复内容列表
        public Hashtable Ev_Search_ContentEvaluate_List
            (
            string ItemName,
            string ParentID,
            string IsAll,

            int PageIndex,
            int PageSize
            )
        {
            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();
            int PageCount = 0;
            int TotalCount = 0;


            DataSet ds = new XJX.DataLayer.Evaluate(ConnToData).Ev_Search_ContentEvaluate_List
                    (ItemName, ParentID, IsAll, "ContentEvaluate", PageIndex, PageSize, out PageCount, out TotalCount);
            dt = ds.Tables[0];

            ArrayList data = Common.DataTable2ArrayList(dt);

            ht["PageCount"] = PageCount;//页数,将在哈希表中输出成字符串。
            ht["RecordCount"] = TotalCount;//记录总数
            ht["rows"] = data;

            return ht;
        }




    }
}
